package fr.univ.lille1.server.webservice;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import fr.univ.lille1.server.domain.Message;
import fr.univ.lille1.server.manager.MessageManager;

@Path("/message")
@Stateless
@LocalBean
@Produces("application/json")
public class MessageWebService {

	@EJB
	private MessageManager messageManager;

	@PUT
	public Message addMessage(@FormParam("userId") int userId,
			@FormParam("title") String title,
			@FormParam("content") String content,
			@FormParam("gpsLat") float gpsLat,
			@FormParam("gpsLong") float gpsLong) {
		return messageManager.addMessage(userId, title, content, gpsLat, gpsLong);
	}

	@POST
	public Message editMessage(@FormParam("id") int id, @FormParam("content") String content) {
		return messageManager.editMessage(id, content);
	}

	@GET
	@Path("{id}")
	public Message findMessageById(@PathParam("id") int id) {
		return messageManager.findMessageById(id);
	}

	@GET
	@Path("latitude/{latitude}/longitude/{longitude}/distance/{distance}")
	public List<Message> findMessagesByLocation(@PathParam("latitude") float latitude,
			@PathParam("longitude") float longitude, @PathParam("distance") float distance) {
		return messageManager.findMessagesByLocation(latitude, longitude, distance);
	}
	
	@POST
	@Path("{id}/like")
	public Message likeMessage(@PathParam("id") int id, @FormParam("userId") int userId){
		return messageManager.likeMessage(id, userId);
	}
	
	@POST
	@Path("{id}/dislike")
	public Message dislikeMessage(@PathParam("id") int id, @FormParam("userId") int userId){
		return messageManager.dislikeMessage(id, userId);
	}
	
	@POST
	@Path("{id}/alert")
	public Message alertMessage(@PathParam("id") int id, @FormParam("userId") int userId){
		return messageManager.alertMessage(id, userId);
	}
	
	@GET
	@Path("user/{userId}")
	public List<Message> findMessagesByUser(@PathParam("userId") int userId) {
		return messageManager.findMessagesByUser(userId);
	}

}
